/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.beyondsoft.sabg.edu.service.core.impl;

import com.beyondsoft.sabg.edu.model.db.core.BinaryFile;
import com.beyondsoft.sabg.edu.model.db.core.Image;
import com.beyondsoft.sabg.edu.repository.core.BinaryFileRepository;
import com.beyondsoft.sabg.edu.service.core.BinaryFileService;
import com.beyondsoft.sabg.edu.service.impl.AbstractSimpleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 *
 * @author Liu Jie <jieliu2000@live.com>
 */
@Service
public class BinaryFileServiceImpl extends AbstractSimpleServiceImpl<BinaryFile, BinaryFileRepository> implements BinaryFileService {

    @Autowired
    BinaryFileRepository fileRepository;

    public BinaryFile saveBinaryFile(MultipartFile file) throws IOException {
        BinaryFile binaryFile = new BinaryFile();
        binaryFile.converFromMultipartFile(file);

        binaryFile = fileRepository.save(binaryFile);
        return binaryFile;
    }

    public Image saveImage(MultipartFile file) throws IOException {
        Image binaryFile = new Image();
        binaryFile.converFromMultipartFile(file);
        binaryFile = fileRepository.save(binaryFile);
        return binaryFile;
    }
}
